package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjCheckTemplateStaff;
import com.koron.css2.newProjectCenter.bean.query.PjCheckTemplateStaffQuery;
import com.koron.css2.newProjectCenter.mapper.PjCheckTemplateStaffMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 工程报装-工程验收员工权限单条更新
 */
public class PjCheckTemplateStaffUpdate implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjCheckTemplateStaffMapper pjCheckTemplateStaffMapper = factory.getMapper(PjCheckTemplateStaffMapper.class);

            PjCheckTemplateStaff pjCheckTemplateStaff = JsonUtils.objectToPojo(req.getData(),PjCheckTemplateStaff.class);

            // 20220607: 一个账户只能有一个部门的权限
            String checkStaff = pjCheckTemplateStaff.getCheckStaff();
            PjCheckTemplateStaffQuery pjCheckTemplateStaffQuery = new PjCheckTemplateStaffQuery();
            pjCheckTemplateStaffQuery.setCheckStaff(checkStaff);
            PjCheckTemplateStaff checkStaffBean = pjCheckTemplateStaffMapper.getSingle(pjCheckTemplateStaffQuery);
            if (checkStaffBean != null) {
                return MessageBean.create(Constant.MESSAGE_INT_FAIL,"一个账户只能有一个部门的权限",null);
            }
            // 1. updateName,updateAccount,updateTime
            pjCheckTemplateStaff.setUpdateInfo(userInfo);
            // 2. 更新数据
            pjCheckTemplateStaffMapper.update(pjCheckTemplateStaff);
            return MessageBean.create(Constant.MESSAGE_INT_SUCCESS,"工程验收员工权限单条更新成功",null);
        } catch (Exception e) {
            logger.error("工程验收员工权限单条更新失败",e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL,"工程验收员工权限单条更新失败",null);
        }
    }
}
